from RequestAPI import BookAPI

class BookManager:
    def __init__(self):
        self.api = BookAPI()
        self.menu_options = {
            '1': 'Get books',
            '2': 'Add book',
            '3': 'Update book',
            '4': 'Delete book',
            '5': 'Exit'
        }

    def display_menu(self):
        print("\nBook Management System")
        for key, value in self.menu_options.items():
            print(f"{key}. {value}")

    def validate_input(self, choice):
        return choice in self.menu_options1

    def execute(self):
        while True:
            self.display_menu()
            choice = input("Enter your choice (1-5): ")
            
            if not self.validate_input(choice):
                print("Invalid choice. Please try again.")
                continue
                
            if choice == '5':
                print("Exiting...")
                break
                
            if choice == '1':
                print(self.api.get_book())
            elif choice == '2':
                print(self.api.post_book())
            elif choice == '3':
                print(self.api.put_book())
            elif choice == '4':
                print(self.api.delete_book())

if __name__ == "__main__":
    manager = BookManager()
    manager.execute()